package com.academico.web.servlet.curso;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.academico.dao.CursoDAO;
import com.academico.model.Curso;
import com.academico.web.servlet.BaseServlet;

public class PopulateCursoServlet extends BaseServlet {

	private static final long serialVersionUID = 2942106139227622694L;

	@Override
	public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<Curso> cursos = loadAllCursos();
		
		setAttributeToRequest(request, "cursos", cursos);
		forward("curso.jsp", request, response);
		
	}

	private List<Curso> loadAllCursos() {
		CursoDAO cursoDAO = new CursoDAO();
		List<Curso> listaCursos = cursoDAO.findAll();
		return listaCursos;
	}

}
